package com.ncloud.msg.service.impl;

import com.ncloud.msg.entity.Email;
import com.ncloud.msg.mapper.EmailMapper;
import com.ncloud.msg.service.MailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * Created by shiqiang on 2017/5/8.
 */
@Service
public class MailServiceImpl implements MailService {
    @Autowired
    private EmailMapper emailMapper;
    @Override
    @Transactional(isolation = Isolation.SERIALIZABLE)
    public List<Email> getEmails(String msgCode, int limit) {
        if(limit<=0){
            limit = 10;
        }
        return emailMapper.getEmailInfos(msgCode,limit);
    }

    @Override
    public int updateEmail(Email email) {
        return emailMapper.updateEmail(email);
    }

    @Override
    public int insertEmailHistory(Long msgId) {
        return emailMapper.insertHisEmail(msgId);
    }

    @Override
    public int deleteEmail(Long msgId) {
        return emailMapper.deleteEmailById(msgId);
    }
}
